package thread;

public class Demo25 {
    private static Object locker1=new Object();
    private static Object locker2=new Object();
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            System.out.println("A");

            //存在这样的概率,t1先执行了打印和notify,然后t2才执行wait,意味着通知来的早了,t2错过了,导致t2无人唤醒
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            //A通知B
            synchronized (locker1){
                locker1.notify();
            }
        });
        Thread t2=new Thread(()->{

            //b进行等待
            synchronized (locker1){
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //A通知之后再进行打印B
            System.out.println("B");
            synchronized (locker2){
                locker2.notify();
            }
        });
        Thread t3=new Thread(()->{

            synchronized (locker2){
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("C");
        });
        t1.start();
        t2.start();
        t3.start();
    }
    }

